DOCUMENTS = gnutella-wiki.sgml gruppo-wiki.sgml

TARGETS = $(DOCUMENTS:.sgml=.html)

SED = /bin/sed
TIDY = /usr/bin/tidy
PSNUP = /usr/bin/psnup
ICONV = /usr/bin/iconv
PS2PDF = /usr/bin/ps2pdf
ASPELL = /usr/bin/aspell
SVN2CL = /usr/bin/svn2cl
DOCBOOK2HTML = /usr/bin/docbook2html
DOCBOOK2PDF = /usr/bin/docbook2pdf
DOCBOOK2PS = /usr/bin/docbook2ps
DOCBOOK2RTF = /usr/bin/docbook2rtf
DOCBOOK2TXT = /usr/bin/docbook2txt


all: $(TARGETS)

spell: $(DOCUMENTS)
	$(ASPELL)		\
	--lang=it_IT		\
	--home-dir=$(PWD)	\
	--personal=.aspell-dict	\
	--ignore-case=true	\
	--mode=sgml		\
	--encoding=utf-8	\
	check			\
	$<

log:
	@$(SVN2CL) -i		\
		--stdout	\
		--authors=.namerc .

clean:
	-@for ext in html pdf ps rtf txt ;	\
	do					\
		rm -f *.$$ext ;			\
	done

%.html: %.sgml
	$(DOCBOOK2HTML) --nochunks					\
	-i 'remote'							\
	-i 'wikionly'							\
	-d p2p-wiki.dsl#html						\
	$^
	-@$(TIDY)							\
	-config .tidyrc							\
	$(^:.sgml=.html)						\
	> $(^:.sgml=.htm)
	-@$(SED)							\
	-e 's/class="c1"/align="justify"/g'				\
	-e 's/class="c2"/style="list-style-type: opencircle;"/g'	\
	$(^:.sgml=.htm)							\
	> $(^:.sgml=.html)
	-@rm -f $(^:.sgml=.htm)

%.pdf: %.sgml
	$(DOCBOOK2PDF)			\
	-d p2p-wiki.dsl#print		\
	$^

%.ps: %.sgml
	$(DOCBOOK2PS)			\
	-i 'useeps'			\
	-d p2p-wiki.dsl#print		\
	$^

%-duplex.ps: %.ps
	$(PSNUP) -2 -pa4 $^ > $@

%-duplex.pdf: %-duplex.ps
	$(PS2PDF) -sPAPERSIZE=a4 $^ $@

%.rtf: %.sgml
	$(DOCBOOK2RTF)			\
	-d p2p-wiki.dsl#print		\
	$^

%.txt: %.sgml
	$(DOCBOOK2TXT)			\
	-d p2p-wiki.dsl#html			\
	$^
	@$(ICONV) -f 'ISO_8859-1' 	\
		-t 'UTF-8' -o 		\
		$(^:.sgml=-utf8.txt)	\
		$(^:.sgml=.txt)
	-@mv -f $(^:.sgml=-utf8.txt) $(^:.sgml=.txt)
